<?php

include("config/config.php");

try
{  
  $dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
  /*** $message = a message saying we have connected ***/
  
  /*** set the error mode to excptions ***/
  $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  /*** prepare the select statement ***/
  $stmt = $dbh->prepare("select servicio
                           from pa_pagos 
                          where anio = :anio");
  
  /*** bind the parameters ***/
  
  $anioo = "2013";
  
  $stmt->bindParam(':anio', $anioo, PDO::PARAM_STR);
  
  /*** execute the prepared statement ***/
  $stmt->execute();
  
  /*** check for a result ***/
  $rows = $stmt->fetchAll();
  
  foreach ($rows as $row)
  {
    // $result = array_push_assoc($result, 'servicio', $row[0]); 
    //$result['servicio'] = $row[0];
    $aux['servicio'] = $row[0];
    $result[] = $aux;
  }
  //{
  
}
catch(Exception $e)
{
  /*** if we are here, something has gone wrong with the database ***/
  //$message = 'We are unable to process your request. Please try again later"';
  echo "Error " . $e->getMessage();
}
 
/* 
if ( isset($_POST['anio']) && $_POST['anio'] == "2013" )
{

  $result = array( 
                   array ('servicio' => 'edenor' ),
                   array ('servicio' => 'fibertel' ),
                   array ('servicio' => 'cablevision' )
                  );

}
elseif ( isset($_POST['anio']) && $_POST['anio'] == "2014" )
{

  $result = array( 
                   array ('servicio' => 'cablevision' ),
                   array ('servicio' => 'movistar' )
                  );

}
else
  $result = array();
  
  $result = array( 
                   array ('servicio' => 'edenor' ),
                   array ('servicio' => 'fibertel' ),
                   array ('servicio' => 'cablevision' )
                  );  
*/

/*$result = array( 
                   array ('servicio' => 'edenor' ),
                   array ('servicio' => 'fibertel' ),
                   array ('servicio' => 'cablevision' )
                  );  */

echo json_encode($result);

?>